package com.qdu.service.impl;

import com.qdu.bean.Consumable;
import com.qdu.mapper.ConsumableMapper;
import com.qdu.service.ConsumableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ConsumableServiceIml implements ConsumableService {

    @Autowired
    ConsumableMapper consumableMapper;

    @Override
    public List<Consumable> getConsumable() {
        List<Consumable> consumable = consumableMapper.getConsumable();
        return consumable;
    }

    @Override
    public void updateStore(String id) {
        Consumable consumable = consumableMapper.queryStoreById(id);
        if(consumable.getStorage()>=5) {
            consumable.setStorage(consumable.getStorage() - 5 );
            consumable.setDecrement(consumable.getDecrement() + 5 );
            consumable.setId(id);
            consumableMapper.updateStore(consumable);
        }

    }

    @Override
    public boolean orderConsumable(Consumable consumable) {
        consumableMapper.orderConsumable(consumable);
        return true;
    }

    @Override
    public List<Consumable> queryAllConsumable() {
        return consumableMapper.queryAllConsumable();
    }
}
